﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

namespace SIS.DataAccess
{
	/// <summary>
	/// Author: hieunv
	/// </summary>
	class Student : System.Data.DataTable
	{
		public const string STUDENT_ID = "ID";
		public const string STUDENT_NAME = "name";
		public const string DEPARTMENT_NAME = "dept_name";
		public const string TOTAL_CREDIT = "tot_cred";
		public Student()
			: base("Student")
		{
			var id = new System.Data.DataColumn(STUDENT_ID, typeof(string));
			id.AllowDBNull = false;
			id.Unique = true;

			var name = new System.Data.DataColumn(STUDENT_NAME, typeof(string));
			name.AllowDBNull = false;
			
			var departmentName = new System.Data.DataColumn(DEPARTMENT_NAME, typeof(string));
			departmentName.AllowDBNull = true;

			var totalCredits = new System.Data.DataColumn(TOTAL_CREDIT, typeof(int));
			totalCredits.AllowDBNull = true;

			this.Columns.Add(id);
			this.Columns.Add(name);
			this.Columns.Add(departmentName);
			this.Columns.Add(totalCredits);

			this.PrimaryKey = new System.Data.DataColumn[] { id };
		}

		public static DataTable GetStudentIDs(string departmentName)
		{
			
			var ids = new DataTable();
			DataServices.ExecuteQuery(QueryType.SELECT, CommandType.Text, "SELECT ID FROM student WHERE dept_name ='" + departmentName + "'", null, ids);
			return ids;
		}
	}
}
